package com.luanye.enjoy.controller;

import com.luanye.enjoy.dto.DynamicDTO;
import com.luanye.enjoy.service.DynamicService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dynamic")
@AllArgsConstructor
public class DynamicController {

    private final DynamicService dynamicService;

    @PostMapping("/publish")
    public RespBean create(@RequestBody DynamicDTO dto){
        return dynamicService.publish(dto);
    }

    @GetMapping("/like")
    public RespBean like(Integer id){
        return dynamicService.like(id);
    }

    @GetMapping("/hot")
    public RespBean getHotDynamic(Integer current){
        return dynamicService.queryHotDynamic(current);
    }

    @GetMapping("/query")
    public RespBean queryDynamicById(Integer id){
        return dynamicService.queryDynamicById(id);
    }

    @GetMapping("/my")
    public RespBean getMyDynamic(){
        return dynamicService.getMyDynamic();
    }

    @GetMapping("/{topicId}")
    public RespBean getDynamicByTopic(@PathVariable("topicId") Integer topicId
    ){
        return dynamicService.getDynamicByTopic(topicId);
    }

    @DeleteMapping("/{id}")
    public RespBean deleteDynamic(@PathVariable("id") Integer id){
        return dynamicService.deleteById(id);
    }

    @GetMapping("/of/follow")
    public RespBean queryBlogOfFollow(
            @RequestParam("lastId") Long max, @RequestParam(value = "offset", defaultValue = "0") Integer offset){
        return dynamicService.queryBlogOfFollow(max, offset);
    }
}
